#ifndef _OUTPUT_LOG_H_
#define _OUTPUT_LOG_H_
#include "stdio.h"
#include "stm32f4xx.h"
#define UART_LOG_OUT 1
// #define UART1_USED  1
extern unsigned char g_debug_threshold;
extern unsigned char ELOG_OUTPUT_LVL;

#define MSG_OUT(level, ...) \
    message_out(level, __VA_ARGS__)

#define DEBUG_MSG(level, ...) \
    debug_message_out(level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)

void output_log_uart_init(unsigned char debug_threshold);

void debug_message_out(unsigned char level, const char *file, int line, const char *func, const char *format, ...);
void message_out(unsigned char level, const char *formate, ...);

#ifdef __cplusplus
extern "C"
{
#endif

    /* 日志级别 */
#define ELOG_LVL_ASSERT 0
#define ELOG_LVL_ERROR 1
#define ELOG_LVL_WARN 2
#define ELOG_LVL_INFO 3
#define ELOG_LVL_DEBUG 4
#define ELOG_LVL_VERBOSE 5

/* 设置日志级别 */
//#define ELOG_OUTPUT_LVL ELOG_LVL_DEBUG

/* 断言(Assert)  */
#define LOG_A(args, ...)                                                              \
    do                                                                                \
    {                                                                                 \
        if (ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT)                                       \
        {                                                                             \
            printf("[A/%s Line:%.4d] " args "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
        }                                                                             \
    } while (0)

/* 错误(Error) */
#define LOG_E(args, ...)                                                              \
    do                                                                                \
    {                                                                                 \
        if (ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR)                                        \
        {                                                                             \
            printf("[E/%s Line:%.4d] " args "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
        }                                                                             \
    } while (0)

/* 警告(Warn) */
#define LOG_W(args, ...)                                                              \
    do                                                                                \
    {                                                                                 \
        if (ELOG_OUTPUT_LVL >= ELOG_LVL_WARN)                                         \
        {                                                                             \
            printf("[W/%s Line:%.4d] " args "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
        }                                                                             \
    } while (0)

/* 信息(Info) */
#define LOG_I(args, ...)                                                              \
    do                                                                                \
    {                                                                                 \
        if (ELOG_OUTPUT_LVL >= ELOG_LVL_INFO)                                         \
        {                                                                             \
            printf("[I/%s Line:%.4d] " args "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
        }                                                                             \
    } while (0)

    /* 调试(Debug) */
#define LOG_D(args, ...)                                                              \
    do                                                                                \
    {                                                                                 \
        if (ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG)                                        \
        {                                                                             \
            printf("[D/%s Line:%.4d] " args "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
        }                                                                             \
    } while (0)

    /* 详细(Verbose) */
#define LOG_V(args, ...)                                                              \
    do                                                                                \
    {                                                                                 \
        if (ELOG_OUTPUT_LVL >= ELOG_LVL_VERBOSE)                                      \
        {                                                                             \
            printf("[V/%s Line:%.4d] " args "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
        }                                                                             \
    } while (0)

#ifdef __cplusplus
}
#endif

#endif
